package com.atguigu.day19.work;

import java.util.ArrayList;
import java.util.Random;

public class Work03 {
    public static void main(String[] args) {
        ArrayList nums = getNum();
        System.out.println("随机数" + nums);
        ArrayList maxList = getTop(nums);
        System.out.println("前三最大的:" + maxList);
        System.out.println("删除后:" + nums);
    }

    public static ArrayList<Integer> getNum() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            int n = random.nextInt(100) + 1;
            list.add(n);
        }
        return list;
    }

    public static ArrayList<Integer> getTop(ArrayList<Integer> list) {
        ArrayList<Integer> maxList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Integer max = (Integer) list.get(0);
            for (int j = 0; j < list.size(); j++) {
                Integer num = (Integer) list.get(j);
                if (max < num) {
                    max = num;
                }
            }
            maxList.add(max);
            while (list.contains(max)) {
                list.remove(max);
            }
        }
        return maxList;
    }
}
